%GLOBAL CWD; %LET CWD = %SUBSTR(%SYSGET(SAS_EXECFILEPATH), 1, %EVAL(%LENGTH(%SYSGET(SAS_EXECFILEPATH)) - %LENGTH(%SYSGET(SAS_EXECFILENAME)) - 1));
%INCLUDE "&CWD\TOOLS.SAS";

/* SET ELI & CLUSTER */
%LET ELI = FC011;
%LET CLUSTER = 01A;

/* IDENTIFYING HANDLE */
%LET COM = &ELI._&CLUSTER.;

/* ITEM-SPECIFIC RIGHT HAND SIDE VARIABLES */
%LET RHS = 
    A1 A2 A3 B1 B2 B3 C1 D1 D2 D3 E1 E2 F1 G1 H1 MNAMT MNAMTSQ  
    ;

*%LET STYR = 0203; /* this is the original */
%LET STYR = 0203; 
%LET FIRSTPER = 20&STYR.;
%LET LASTPER = 200709;
%LET STDUM = D&STYR.;
*%LET RHYRS = D0204 -- D0709; /* this is the original */
%LET RHYRS = D0204 -- D0709;

%LET NSPER = %COUNTMONTHS(&FIRSTPER, &LASTPER);
%LET NVEC = %EVAL(&NSPER + %COUNTWORDS(&RHS));

/* DEFINE ITEM-SPECIFIC PRICE EDITS */
%MACRO EDITS;   
    IF FULLSAMP_EFFPR_WOTX>1 THEN DELETE; *OUTLIER REMOVAL;
%MEND;

/* DEFINE ITEM-SPECIFIC DUMMIES */
%MACRO VARS;
    
    A1=(A="A1"); A2=(A="A2"); A3=(A="A3"); A4=(A="A4");
    ARRAY AARRAY (5) A1-A4 A99SP;
        DO COUNT=1 TO 5;
        IF A="" THEN AARRAY(COUNT)=.;
    END;

    B1=(B="B1"); B2=(B="B2"); B3=(B="B3"); 
    B99SP=(B="B99");
    ARRAY BARRAY (4) B1-B3 B99SP;
        DO COUNT=1 TO 4;
        IF B="" THEN BARRAY(COUNT)=.;
    END;

    C1=(C="C1"); C2=(C="C2");
    ARRAY CARRAY (2) C1-C2;
        DO COUNT=1 TO 2;
        IF C="" THEN CARRAY(COUNT)=.;
    END;

    D1=(D="D1"); D2=(D="D2"); D3=(D="D3"); D4=(D="D4");
    D99SP=(D="D99");
    ARRAY DARRAY (5) D1-D4 D99SP;
        DO COUNT=1 TO 5;
        IF D="" THEN DARRAY(COUNT)=.;
    END;

    E1=(E="E1"); E2=(E="E2"); E3=(E="E3");
    ARRAY EARRAY (3) E1-E3;
        DO COUNT=1 TO 3;
        IF E="" THEN EARRAY(COUNT)=.;
    END;

    F1=(F="F1"); F2=(F="F2"); 
    ARRAY FARRAY (2) F1-F2;
        DO COUNT=1 TO 2;
        IF F="" THEN FARRAY(COUNT)=.;
    END;

    G1=(G="G1"); 
    G99SP=(G="G99");
    ARRAY GARRAY (2) G1 G99SP;
        DO COUNT=1 TO 2;
        IF G="" THEN GARRAY(COUNT)=.;
    END;

    H1=(H="H1");  
    H99SP=(H="H99");
    ARRAY HARRAY (2) H1 H99SP;
        DO COUNT=1 TO 2;
        IF H="" THEN HARRAY(COUNT)=.;
    END;
    
    *ELIMINATE QUOTES WITH MISSING SPEC VARIABLES;
    *INCLUDE APPROPRIATE LIST OF SPEC VARIABLES HERE AND ELSEWHERE;
    *MODIFY SIZE OF SPECARRAY AS NEEDED TO NUMBER OF YOUR SPEC VARIABLES PLUS 5;
    
    ARRAY SPECARRAY (*) A1 A2 A3 A4 B1 B2 B3 B99SP C1 C2 D1 D2 D3 D4 D99SP E1 E2 E3 F1 F2
    G1 G99SP H1 H99SP
    DISCDEP--OTHSTORE;
        DO COUNT=1 TO DIM(SPECARRAY);
        IF SPECARRAY(COUNT)=. THEN DELETE;
    END;


%MEND;

LIBNAME IN "&CWD\DATA";
LIBNAME OUT "&CWD\DATA";

FILENAME OUTLOGS "&CWD\OUTPUT\LOGINDEXES.XLS";
FILENAME OUTCONTS "&CWD\OUTPUT\LOGCONTRIBS.XLS";
FILENAME OUTDISCS "&CWD\OUTPUT\DISCOUNTS.XLS";
FILENAME OUTPCTLS "&CWD\OUTPUT\PCTLS.XLS";

%INCLUDE "&CWD\TABLESTOBUILD.SAS";
